package ge.devfest.hackathon.gg;

import ge.devfest.hackathon.gg.model.Activity;
import ge.devfest.hackathon.gg.utils.IBaseActivityFragment;
import android.location.Location;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;

public class ActivityMapFragment extends SupportMapFragment implements IBaseActivityFragment {

	private static final String TAG = "ActivityMapFragment";
	
	private GoogleMap mMap;
	private LatLng mTbilisiLatLng = new LatLng(41.703767, 44.793881);
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		LinearLayout mapFragmentView = (LinearLayout) inflater.inflate(R.layout.activity_map_fragment, null);
		FrameLayout leftSpace = (FrameLayout) mapFragmentView.findViewById(R.id.left_space);
		FrameLayout mapContainer = (FrameLayout) mapFragmentView.findViewById(R.id.map_container);
		mapContainer.addView(super.onCreateView(inflater, container, savedInstanceState));
		leftSpace.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
			}
		});
		mMap = getMap();
		if (mMap != null) {
			mMap.setMyLocationEnabled(true);
//			mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mTbilisiLatLng, 13));
		}
		return mapFragmentView;
	}
	
	@Override
	public void onPause() {
		super.onPause();
		System.out.println(mMap.getMyLocation());
	}

	@Override
	public void initContentView(Activity activity, Bundle savedInstanceState) {
		// noop
	}

	@Override
	public void saveActivity(Activity activity) {
		if (mMap != null) {
			Location l = mMap.getMyLocation();
			activity.setLatitude(l.getLatitude());
			activity.setLongitude(l.getLongitude());
		}
	}
	
}
